package com.lanmaoly.cunzheng;

import sun.net.www.protocol.http.HttpURLConnection;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class URLTest {

    public static void main(String[] args) throws IOException {
        URL url = new URL("http://192.168.254.113:8088/chain/evidence/get");
        HttpURLConnection urlConnection = new HttpURLConnection(url, null);
//        URLConnection urlConnection = url.openConnection();
        urlConnection.setDoOutput(true);
        urlConnection.setReadTimeout(300);
        urlConnection.setConnectTimeout(300);
        OutputStream ops = urlConnection.getOutputStream();
        ops.write("test".getBytes());
        InputStream inputStream = urlConnection.getInputStream();
        int read = 0;
        int numRead;
        byte[] bytes = new byte[1024];
        while ((numRead = inputStream.read(bytes, read, 512)) != -1) {
            read += numRead;
        }
        String str = new String(bytes);
        Pattern p = Pattern.compile("\\s*|\t|\r|\n");
        Matcher m = p.matcher(str);
        String s = m.replaceAll("");
        System.out.println(s);
    }
}
